package com.songcha.module_vip.ui.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.songcha.library_common.ui.dialog.CustomDialog
import com.songcha.library_common.ui.view.CustomButton
import com.songcha.library_common.util.ClipboardUtil
import com.songcha.library_common.util.ScreenUtil
import com.songcha.library_common.util.ToastUtil
import com.songcha.library_common.util.dp2px
import com.songcha.module_vip.R


class CustomServiceDialog(context: Context): CustomDialog(context) {
    private var mCustomService = ""

    init {
        setDialogTitle("")
        setDialogMsg("")
        setShowBtn(false)
        setWidth(ScreenUtil.getScreenWidth())
        setGravity(Gravity.BOTTOM)
        setAnim(com.songcha.library_common.R.style.dialogBottomSlideWindowAnim)
        setRadius(floatArrayOf(10f.dp2px(),10f.dp2px(),0f,0f))
    }

    fun setCustomService(customService:String){
        mCustomService = customService
    }

    override fun hasView(): Boolean {
        return true
    }

    override fun getView(root: ViewGroup): View? {
        val view = LayoutInflater.from(context).inflate(R.layout.vip_dialog_custom_service,root,false)
        val ivClose = view.findViewById<ImageView>(R.id.vip_dialog_iv_close)
        ivClose.setOnClickListener {
            dismiss()
        }
        val btn = view.findViewById<CustomButton>(R.id.vip_dialog_btn)
        btn.text = mCustomService
        btn.setOnClickListener{
            try{
                ClipboardUtil.copyText(context,mCustomService)
                ToastUtil.show("已复制客服联系方式")
                val intent = context.packageManager.getLaunchIntentForPackage("com.tencent.mobileqq")
                context.startActivity(intent)
            }catch (e:Exception){
                e.printStackTrace()
            }
            dismiss()
        }
        return view
    }


}